home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************************
- *
- * Project Name: Templates
- * File Name: cdef.c
- * Author: Rob Neville (IIx)
- * Date: May 17, 1989
- *
- * Description: Template cdef function.
- *
- *************************************************************************************
- *
- * Revision History:
- * 5/17/89 - Original version by Rob Neville (IIx)
- * 6/26/89 - Reved for b2 of Comm Toolbox
- *
- ************************************************************************************/
-
- #include "CMTool.h"
-
- pascal long CDEF(hTH,msg,p1,p2,p3)
- ToolHandle hTH;
- short msg;
- long p1,p2,p3;
- {
- long theErr;
-
- long ToolInit(ToolHandle);
- long ToolDispose(ToolHandle);
- long ToolSuspend(ToolHandle);
- long ToolResume(ToolHandle);
- long ToolMenu(ToolHandle,short,short);
- long ToolEvent(ToolHandle,EventRecord *);
- long ToolActivate(ToolHandle);
- long ToolDeactivate(ToolHandle);
- long ToolReset(ToolHandle);
- long ToolIdle(ToolHandle);
- long ToolAbort(ToolHandle);
- long ToolRead(ToolHandle,CMDataBufferPtr,long,CMCompletorPtr);
- long ToolWrite(ToolHandle,CMDataBufferPtr,long,CMCompletorPtr);
- long ToolStatus(ToolHandle,CMBufferSizes,CMStatFlags *);
- long ToolListen(ToolHandle,CMCompletorPtr,long);
- long ToolAccept(ToolHandle,Boolean);
- long ToolClose(ToolHandle,CMCompletorPtr,Boolean);
- long ToolOpen(ToolHandle,CMCompletorPtr,long);
- long ToolBreak(ToolHandle,long,CMCompletorPtr);
- long ToolIOKill(ToolHandle,short);
- long ToolEnvirons(ToolHandle,ConnEnvironRecPtr);
-
- switch (msg) {
- case TInitMsg:
- theErr = ToolInit(hTH);
- break;
- case TDisposeMsg:
- theErr = ToolDispose(hTH);
- break;
- case TSuspendMsg:
- theErr = ToolSuspend(hTH);
- break;
- case TResumeMsg:
- theErr = ToolResume(hTH);
- break;
- case TMenuMsg:
- theErr = ToolMenu(hTH,(short)p1,(short)p2);
- break;
- case TEventMsg:
- theErr = ToolEvent(hTH,(EventRecord *)p1);
- break;
- case TActivateMsg:
- theErr = ToolActivate(hTH);
- break;
- case TDeactivateMsg:
- theErr = ToolDeactivate(hTH);
- break;
- case TResetMsg:
- theErr = ToolReset(hTH);
- break;
- case TIdleMsg:
- theErr = ToolIdle(hTH);
- break;
- case TAbortMsg:
- theErr = ToolAbort(hTH);
- break;
- case TReadMsg:
- theErr = ToolRead(hTH,(CMDataBufferPtr)p1,p2,(CMCompletorPtr)p3);
- break;
- case TWriteMsg:
- theErr = ToolWrite(hTH,(CMDataBufferPtr)p1,p2,(CMCompletorPtr)p3);
- break;
- case TStatusMsg:
- theErr = ToolStatus(hTH,(CMBufferSizes)p1,(CMStatFlags *)p2);
- break;
- case TListenMsg:
- theErr = ToolListen(hTH,(CMCompletorPtr)p1,p2);
- break;
- case TAcceptMsg:
- theErr = ToolAccept(hTH,(Boolean)p1);
- break;
- case TCloseMsg:
- theErr = ToolClose(hTH,(CMCompletorPtr)p1,(Boolean)p2);
- break;
- case TOpenMsg:
- theErr = ToolOpen(hTH,(CMCompletorPtr)p1,p2);
- break;
- case TBreakMsg:
- theErr = ToolBreak(hTH,p1,(CMCompletorPtr)p2);
- break;
- case TIOKillMsg:
- theErr = ToolIOKill(hTH,(short)p1);
- break;
- case TEnvironsMsg:
- theErr = ToolEnvirons(hTH,(ConnEnvironRecPtr)p1);
- break;
- default: /* we should never get this */
- theErr = TNotSupported; /* I don't support unsupported messages */
- break;
- }
- return (theErr);
- }
-
- long ToolInit(ToolHandle hTH)
- {
- long result = TNoErr;
- PrivatePtr cmPrivate;
- char saved;
-
- if ((**hTH).procID < 3) { /* procID's less than 3 are reserved for the System or are errors */
- debugstr("Pipe is blocked!!! Call New!!;hc;g");
- result = TFailed;
- }
- else /* This portion will change for other Tool Types */
- {
-
- /* Debugger(); */
- saved = HGetState((Handle)hTH);
- HLock((Handle)hTH);
- (**hTH).bufferArray[cmDataIn] = NewPtrClear(1024);
- if ((**hTH).bufferArray[cmDataIn] == nil)
- {
- (**hTH).errCode = MemError();
- return ((**hTH).errCode);
- }
- (**hTH).bufferArray[cmDataOut] = NewPtrClear(1024);
- if ((**hTH).bufferArray[cmDataOut] == nil)
- {
- (**hTH).errCode = MemError();
- DisposPtr((**hTH).bufferArray[cmDataIn]);
- return ((**hTH).errCode);
- }
- HSetState((Handle)hTH,saved);
- cmPrivate = (PrivatePtr)NewPtrClear(sizeof(cmPrivate));
-
- if (cmPrivate == nil)
- {
- (**hTH).errCode = MemError();
- DisposPtr((**hTH).bufferArray[cmDataIn]);
- DisposPtr((**hTH).bufferArray[cmDataOut]);
- result = ((**hTH).errCode);
- }
- (PrivatePtr)(**hTH).cmPrivate = cmPrivate;
- (**hTH).flags |= cmData;
- (**hTH).errCode = TNoErr;
- }
- return (result);
- }
-
- long ToolDispose(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Dispose!!;hc;g");
- result = TFailed;
- }
- else
- DisposPtr((**hTH).cmPrivate); /* dispose my only data structure */
- return (result);
- }
-
- long ToolSuspend(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Suspend!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolResume(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Resume!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolMenu(ToolHandle hTH,short p1,short p2)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3 ) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Menu!! In Handle;hc;g");
- (**hTH).errCode = TFailed;
- }
- if (p1 >= 32767 || p1 <= -32767) { /* Need to check if it is a valid short */
- debugstr("Pipe is blocked!!! Call Menu!! Invalid p1;hc;g");
- (**hTH).errCode = TFailed;
- }
- if (p2 >= 32767 || p2 <= -32768) { /* Need to check if it it a valid short */
- debugstr("Pipe is blocked!!! Call Menu!! Invalid p2;hc;g");
- (**hTH).errCode = TFailed;
- }
- return (result);
- }
-
- long ToolEvent(ToolHandle hTH,EventRecord *theEvent) /* Don't pass this a NullEvent PLEASE */
- ToolHandle hTH;
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Event!! In Handle;hc;g");
- result = TFailed;
- }
- if (theEvent->what <= 0 ) { /* Invalid EventRecord if what < 0 */
- debugstr("Pipe is blocked!!! Call Event!! p1;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolActivate(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Activate!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolDeactivate(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Deactivate!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolReset(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3 ) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Abort!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolIdle(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Abort!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolAbort(ToolHandle hTH)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Abort!!;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolRead(ToolHandle hTH,CMDataBufferPtr p1,long p2,CMCompletorPtr p3)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Start!! In Handle;hc;g");
- result = TFailed;
- }
- if (p1 < 0) { /* Can't be a valid ptr if < 0 */
- debugstr("Pipe is blocked!!! Call Start!! In p1;hc;g");
- result = TFailed;
- }
- if (p2 < 0) {
- debugstr("Pipe is blocked!!! Call Start!! In p2;hc;g");
- result = TFailed;
- }
- if (p3 < 0) { /* Con't be a valid ptr if less than zero */
- debugstr("Pipe is blocked!!! Call Start!! In p3;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolWrite(ToolHandle hTH,CMDataBufferPtr p1,long p2,CMCompletorPtr p3)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Start!! In Handle;hc;g");
- result = TFailed;
- }
- if (p1 < 0) { /* Can't be a valid ptr */
- debugstr("Pipe is blocked!!! Call Start!! In p1;hc;g");
- result = TFailed;
- }
- if (p2 < 0) {
- debugstr("Pipe is blocked!!! Call Start!! In p2;hc;g");
- result = TFailed;
- }
- if (p3 < 0) { /* Can't be a valid ptr */
- debugstr("Pipe is blocked!!! Call Start!! In p3;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolStatus(ToolHandle hTH,CMBufferSizes p1,CMStatFlags *p2)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Status!! In Handle;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Status!! In p1;hc;g");
- result = TFailed;
- }
- else {
- p1[cmDataIn] = 0;
- p1[cmDataOut] = 0;
- }
- if (p2 < 0) {
- debugstr("Pipe is blocked!!! Call Status!! In p2;hc;g");
- result = TFailed;
- }
- else
- *p2 = 0;
- return (result);
- }
-
- long ToolAccept(ToolHandle hTH,Boolean p1)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Accept!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Accept!! In p1;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolClose(ToolHandle hTH,CMCompletorPtr p1,Boolean p2)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Close!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Close!! In p1;hc;g");
- result = TFailed;
- }
- if (p2 < 0) {
- debugstr("Pipe is blocked!!! Call Close!! In p2;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolOpen(ToolHandle hTH,CMCompletorPtr p1,long p2)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Open!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Open!! In p1;hc;g");
- result = TFailed;
- }
- if (p2 < -1) {
- debugstr("Pipe is blocked!!! Call Open!! In p2;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolListen(ToolHandle hTH,CMCompletorPtr p1,long p2)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Listen!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Listen!! In p1;hc;g");
- result = TFailed;
- }
- if (p2 < 0) {
- debugstr("Pipe is blocked!!! Call Listen!! In p2;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
-
- long ToolBreak(ToolHandle hTH,long p1,CMCompletorPtr p2)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Break!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Break!! In p1;hc;g");
- result = TFailed;
- }
- if (p2 < 0) {
- debugstr("Pipe is blocked!!! Call Break!! In p2;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolIOKill(ToolHandle hTH,short p1)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call IOKill!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call IOKill!! In p1;hc;g");
- result = TFailed;
- }
- return (result);
- }
-
- long ToolEnvirons(ToolHandle hTH,ConnEnvironRecPtr p1)
- {
- long result = TNoErr;
-
- if (((**hTH).procID < 3) || ((**hTH).cmPrivate == nil)) { /* Invalid procID or no cmPrivatePtr */
- debugstr("Pipe is blocked!!! Call Environs!!;hc;g");
- result = TFailed;
- }
- if (p1 < 0) {
- debugstr("Pipe is blocked!!! Call Environs!! In p1;hc;g");
- result = TFailed;
- } /* Should set something in case other Tools want to know */
- p1->baudRate = 0; /* no baud rate this is a dummy tool */
- p1->dataBits = 8; /* 8 bit path */
- p1->swFlowControl = 0; /* no software handshaking this is a dummy tool */
- p1->hwFlowControl = 0; /* no hardware handshaking this is a dummy tool */
- p1->channels = cmData; /* Data channel only */
- if (p1->version < 0)
- result = envBadVers; /* version less than zero is BAD */
- if (p1->version > 0)
- result = envVersTooBig; /* version larger than zero is too big at this time */
- return (result);
- }
-